﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"
#include "IElementParametersCustomizer.h"
#include "OwnerPtr.h"
#include "WeakPtr.h"

namespace gcmp
{
    class IDocument;
    class IElement;
    class UniIdentity;

    class GmStructureDefaultElementParametersCustomizer : public NdbObjectSchematic,
        public IElementParametersCustomizer
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, GmStructureDefaultElementParametersCustomizer,
            gcmp::NdbObjectSchematic, BCAA577F - 36C5 - 410E - B9EF - A6EED174F285,
            gmstructure, IElementParametersCustomizer)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(OwnerPtr<IElementParametersCustomizer>, ProxyCustomizer)
        DBOBJECT_DATA_END
    public:
        static void SetElementParametersCustomizer(IElement* pOwnerElement, 
            OwnerPtr<IElementParametersCustomizer> opNewCustomizer);

    public:
        GmStructureDefaultElementParametersCustomizer(IElement* pElement);
        virtual ~GmStructureDefaultElementParametersCustomizer() {}
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; }
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }

        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr) override;
        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual bool IsParameterModifiable(int parameterId) const override;
        virtual bool IsPresetParameter(const UniIdentity& paramDefUid) const override { return true; }
        virtual void FilterParameterValues(const UniIdentity& paramDefUid, 
            std::vector<OwnerPtr<IParameterValueStorage>>& values) const override {}

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override;

    public:
        void SetProxyCustomizer(OwnerPtr<IElementParametersCustomizer> proxyCustomizer);
    };
}
